<?php $row = $cliente->row();?>
<?php $raw = $compra->row();?>
<html>
    <head>
        <title>Confirmaci&oacute;n de su pedido</title>
        <style type="text/css">

            .Stil1 {
                font-family: Verdana, Arial, Helvetica, sans-serif;
                font-size: 12px;
            }


            .Stil2 {
                font-family: Verdana, Arial, Helvetica, sans-serif;
            }


            .odd {
                font-family: Verdana, Arial, Helvetica, sans-serif;
                font-size: 12px;
                background-color : #cccccc;
            }

        </style>
    </head>
    <body>
        <table width="100%" align="center" border="0" cellspacing="0" cellpadding="2" summary="">
            <tr valign="top">
                <td width="10" rowspan="2"></td>
                <td bgcolor="#CCCCCC" align="left" class="Stil1" colspan="2">
                    <h3 class="Stil2">Industria Basica S.A.</h3>
                    Dr. Amadeo Sabattini 5294 (B1678CQR) Caseros<br>
                    Tel: (011) 4512-7555 Fax: 4512-7556<br>
                </td>
                <td width="10" rowspan="2"></td>
            </tr>
            <tr bgcolor="white">
                <td colspan="2">
                    <h3 class="Stil2">Informaci&oacute;n del pedido</h3>
                </td>
            </tr>
        </table>
        <table border="0" cellspacing="0" cellpadding="2" width="100%" summary="">
            <tr class="sectiontableheader">
                <td width="10" rowspan="22"></td>
                <td colspan=2 class="Stil2" bgcolor="#CCCCCC"><b>Datos del pedido</b></td>
                <td width="10" rowspan="22"></td>
            </tr>
            <tr class="Stil1">
                <td><strong>N&uacute;mero de pedido:</strong></td>
                <td><?=$raw->order_id?></td>
            </tr>
            <tr class="Stil1">
                <td><strong>Cliente:</strong></td>
                <td><?=$this->session->userdata('name')?>(<?=$row->username?>)</td>
            </tr>
            <tr class="Stil1">
                <td><strong>Orden de Compra:</strong></td>
                <td><?=$raw->orden_compra?></td>
            </tr>
            <tr class="Stil1">
                <td><strong>Fecha:</strong></td>
                <td><?=date("d/m/y h:m",$raw->cdate)?></td>
            </tr>
            <tr class="sectiontableheader">
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr bgcolor="#CCCCCC" class="sectiontableheader">
                <td colspan="2"><b class="Stil2">Datos del cliente</b></td>
            </tr>
            <tr valign="top" class="Stil1">
                <td width="20%">
                    <strong>Domicilio:</strong>
                </td>
                <td><?=$row->address_1?></td>
            </tr>
            <tr class="Stil1">
                <td><strong>Localidad:</strong></td>
                <td><?=$row->city?></td>
            </tr>
            <tr class="Stil1">
                <td><strong>Provincia:</strong></td>
                <td><?=$row->state?></td>
            </tr>
            <tr class="Stil1">
                <td><strong>Codigo Postal:</strong></td>
                <td><?=$row->zip?></td>
            </tr>
            <tr class="Stil1">
                <td><strong>Tel&eacute;fono:</strong></td>
                <td><?=$row->phone_1?></td>
            </tr>
            <tr class="Stil1">
                <td><strong>Fax:</strong></td>
                <td><?=$row->fax?></td>
            </tr>
            <tr>
                <td colspan=2>&nbsp;</td>
            </tr>
            <tr>
                <td colspan=2>&nbsp;</td>
            </tr>
            <tr>
                <td colspan=2>&nbsp;</td>
            </tr>
            <tr bgcolor="#CCCCCC" class="Stil2">
                <td colspan="2"><b>Pedido</b></td>
            </tr>
            <tr>
                <td colspan="2">
                    <table width="100%" cellspacing="0" cellpadding="2" border="0" summary="">
                        <tr align="center" class="Stil1">
                            <th>Cantidad</th>
                            <th>Codigo</th>
                            <th>Descripcion</th>
                            <th align="right">Precio</th>
                            <th align="right">Total</th>
                        </tr>
                        <?php
                        $total_price=$i=0;$color=1;
                        $query = $this->db->query("SELECT * FROM order_item WHERE order_id=".$raw->order_id);
                        foreach ($query->result() as $row):
                            $total_price += $row->product_quantity*$row->product_item_price;
                            ?>
                            <?php if($i++%2==0):?>
                        <tr align="right" class="Stil1">
                                <?else:?>
                        <tr align="right" class="odd">
                                <?php endif;?>
                            <td align="center"><?php echo $row->product_quantity; ?></td>
                            <td align="center"><?php echo $row->order_item_sku; ?></td>
                            <td align="left"><?php echo $row->order_item_name; ?></td>
                            <td align="right">$<?php echo $row->product_item_price; ?></td>
                            <td align="right">$<?php echo $row->product_quantity*$row->product_item_price;?></td>
                        </tr>
                        <?php endforeach;
                        $query = $this->db->query("SELECT extra_field_1, extra_field_2, extra_field_3, extra_field_5 FROM users WHERE id=".$this->session->userdata('id'));
                        if ($query->num_rows() > 0)
                            $row=$query->row();

                        $order_total = $total_price;
                        $bonificacion = ($order_total * $row->extra_field_3) / 100;
                        $iva = (($order_total - $bonificacion) * $row->extra_field_1) / 100;
                        $percepcion = (($order_total - $bonificacion) * $row->extra_field_2) / 100;
                        $total = $order_total - $bonificacion + $iva + $percepcion;

                        if ($row->extra_field_3=="51.50") {
                            $titulo="Bonificaci&oacute;n : 50%+3%";
                        }elseif ($row->extra_field_3=="53.925") {
                            $titulo="Bonificaci&oacute;n : 50%+5%+3%";
                        } elseif ($row->extra_field_3=="56.35") {
                            $titulo="Bonificaci&oacute;n : 50%+10%+3%";
                        } elseif ($row->extra_field_3=="41.80") {
                            $titulo="Bonificaci&oacute;n : 40%+3%";
                        } else {
                            $titulo="Bonificaci&oacute;n : 3%";
                        }

                        ?>
            </tr>
            <tr class="Stil1">
                <td colspan="5" align="right">&nbsp;&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr class="Stil1">
                <td colspan="3">&nbsp;</td>
                <td align="right"><strong>Sub Total</strong></td>
                <td align="right">$<?php echo $total_price; ?></td>
            </tr>
            <tr align=left class="Stil1">
                <td colspan="3">&nbsp;</td>
                <td align="right"><strong><?=$titulo;?></strong></td>
                <td align="right">($<?= number_format($bonificacion, 2, '.', ' ');?>)</td>
            </tr>
            <tr align=left class="Stil1">
                <td colspan="3">&nbsp;</td>
                <td align="right"><strong>IVA</strong></td>
                <td align="right">$<?= number_format($iva, 2, '.', ' ');?></td>
            </tr>
            <tr align=left class="Stil1">
                <td colspan="3">&nbsp;</td>
                <td align="right"><strong>Percepci&oacute;n IBB</strong></td>
                <td align="right">$<?= number_format($percepcion, 2, '.', ' ');?></td>
            </tr>
            <tr class="Stil1">
                <td colspan="3">&nbsp;</td>
                <td align="right"><b>Total:</b></td>
                <td align="right"><b>$<?= number_format($total, 2, '.', ' ');?></b></td>
            </tr>
            <tr class="Stil1">
                <td colspan="5" align="left" style="font-size : 10px;">
                    No incluye, si correspondiere, Percepcion de Ingresos Brutos
                    <br>Incluye descuento adicional del 3%
                </td>
            </tr>
            <tr class="Stil1">
                <td colspan="5" align="left" style="font-size : 10px;"></td>
            </tr>
        </table>
    </td>
</tr>
<tr class="sectiontableheader">
    <td colspan="2">&nbsp;</td>
</tr>
<tr bgcolor="#CCCCCC" class="sectiontableheader">
    <td colspan="2"><b class="Stil2">Mensaje del cliente:</b></td>
</tr>
<tr>
    <td colspan="2"><?php echo $raw->customer_note; ?></td>
</tr>
<tr bgcolor="#CCCCCC" class="sectiontableheader">
    <td colspan="2" class="Stil1">Gracias por su compra.</td>
</tr>
</table>
<p class="Stil2">&nbsp;</p>
</body>
</html>
